﻿#ifndef QLYAVPACKET_H
#define QLYAVPACKET_H
#include <QTypeInfo>

extern "C" {
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
}

class QlyAVCodecContext;

class QlyAVPacket
{
public:
    QlyAVPacket();
    ~QlyAVPacket();
    QlyAVPacket(const QlyAVPacket &source);
    QlyAVPacket & operator= (const QlyAVPacket & source);
    unsigned int streamIndex() {return pPacket->stream_index;}
    void setStreamIndex(unsigned int index);
    void changeTimeBase(AVRational bq, AVRational cq, enum AVRounding rnd);
    /**
     * @brief compare_ts
     * @param timestamp
     * @return  -1 表示当前帧的时间小于 timestamp， 1 表示大于， 0 表示相等
     */
    int compare_ts(double timestamp);
    void adjustTime(double timestamp);
    void reset();
    AVPacket *ptr() {return pPacket;}
//private:
    AVPacket * pPacket = nullptr;
    AVRational m_timeBase;

    int errorcode = 0;
    QlyAVCodecContext * pCodecCtx = nullptr;
};

Q_DECLARE_TYPEINFO(QlyAVPacket, Q_MOVABLE_TYPE);

#endif // QLYAVPACKET_H
